home *** CD-ROM | disk | FTP | other *** search
Wrap
global gSimObject, gTruckObject, gLevelObject on placeBuildings set tempPathList to [:] set totalBlockList to [] set cell to the cell of gTruckObject if the level of gLevelObject = 1 then if the goalCell of gSimObject > 3 then set upperCell to getAt([6, 10, 11, 15, 19], random(5)) set lowerCell to getAt([26, 27, 31, 32, 36, 41], random(6)) else set upperCell to getAt([14, 18, 22, 23, 26, 27], random(6)) set lowerCell to getAt([28, 33, 37, 38, 42, 46], random(6)) end if set buildingList to pickBuildings(2) set buildingList to shuffleList(buildingList) placeOneBuilding(lowerCell, the number of cast (getAt(buildingList, 1) & "." & the gridSize of gSimObject)) placeOneBuilding(upperCell, the number of cast (getAt(buildingList, 2) & "." & the gridSize of gSimObject)) set segmentDataA to makePathSegment(cell, lowerCell) set moveListA to getAt(segmentDataA, 1) set blockListA to getAt(segmentDataA, 2) set segmentDataB to makePathSegment(cell, upperCell) set moveListB to getAt(segmentDataB, 1) set blockListB to getAt(segmentDataB, 2) if count(moveListA) <= count(moveListB) then set tempPathList to appendPathList(tempPathList, moveListA) set totalBlockList to appendBlocks(totalBlockList, blockListA) disconnectBuildings([upperCell, blockListB]) set segmentData to makePathSegment(getLast(tempPathList), upperCell) else set tempPathList to appendPathList(tempPathList, moveListB) set totalBlockList to appendBlocks(totalBlockList, blockListB) disconnectBuildings([lowerCell, blockListA]) set segmentData to makePathSegment(getLast(tempPathList), lowerCell) end if set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1)) set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2)) set segmentData to makePathSegment(getLast(tempPathList), the goalCell of gSimObject) set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1)) set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2)) disconnectBuildings([lowerCell, upperCell, totalBlockList]) else if the level of gLevelObject = 2 then if the goalCell of gSimObject > 4 then set upperCell to getAt([1, 2, 9, 10, 16, 17, 18, 24, 25, 26, 32, 33, 34, 40, 41, 42, 43, 44, 50, 51, 58], random(20)) set middleCell to getAt([75, 82, 90, 97, 105, 112, 119, 120, 126, 127, 128, 134, 135], random(13)) set lowerCell to getAt([76, 77, 78, 79, 84, 85, 86, 87, 91, 92, 93, 94, 99, 100, 101, 102], random(16)) else set upperCell to getAt([7, 8, 14, 15, 21, 22, 23, 28, 29, 30, 35, 36, 37, 40, 41, 42, 43, 44, 48, 49, 56], random(20)) set middleCell to getAt([69, 77, 84, 92, 99, 107, 114, 115, 121, 122, 123, 129, 130], random(13)) set lowerCell to getAt([80, 81, 82, 83, 87, 88, 89, 90, 95, 96, 97, 98, 102, 103, 104, 105], random(16)) end if set buildingList to pickBuildings(3) set buildingList to shuffleList(buildingList) placeOneBuilding(lowerCell, the number of cast (getAt(buildingList, 1) & "." & the gridSize of gSimObject)) placeOneBuilding(middleCell, the number of cast (getAt(buildingList, 2) & "." & the gridSize of gSimObject)) placeOneBuilding(upperCell, the number of cast (getAt(buildingList, 3) & "." & the gridSize of gSimObject)) set segmentDataA to makePathSegment(cell, lowerCell) set moveListA to getAt(segmentDataA, 1) set blockListA to getAt(segmentDataA, 2) set segmentDataB to makePathSegment(cell, middleCell) set moveListB to getAt(segmentDataB, 1) set blockListB to getAt(segmentDataB, 2) if count(moveListA) <= count(moveListB) then set tempPathList to appendPathList(tempPathList, moveListA) set totalBlockList to appendBlocks(totalBlockList, blockListA) disconnectBuildings([middleCell, blockListB]) set segmentData to makePathSegment(getLast(tempPathList), middleCell) else set tempPathList to appendPathList(tempPathList, moveListB) set totalBlockList to appendBlocks(totalBlockList, blockListB) disconnectBuildings([lowerCell, blockListA]) set segmentData to makePathSegment(getLast(tempPathList), lowerCell) end if set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1)) set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2)) set segmentData to makePathSegment(getLast(tempPathList), upperCell) set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1)) set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2)) set segmentData to makePathSegment(getLast(tempPathList), the goalCell of gSimObject) set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1)) set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2)) disconnectBuildings([lowerCell, middleCell, upperCell, totalBlockList]) else if the goalCell of gSimObject > 4 then set upperCell to awayFromRiver([9, 10, 17, 18, 25, 26, 33]) set upmidCell to awayFromRiver([43, 51, 52, 58, 59, 60, 66, 67, 73, 74, 81, 88]) set lomidCell to awayFromRiver([54, 61, 62, 69, 70, 76, 77, 78, 84, 85, 91, 92, 93, 99, 100, 101]) set lowerCell to awayFromRiver([105, 112, 113, 119, 120, 126, 127, 128, 134, 135, 142, 143]) else set upperCell to awayFromRiver([14, 15, 21, 22, 28, 29, 36]) set upmidCell to awayFromRiver([41, 47, 48, 54, 55, 56, 62, 63, 70, 71, 78, 86]) set lomidCell to awayFromRiver([60, 67, 68, 74, 75, 81, 82, 83, 89, 90, 96, 97, 98, 103, 104, 105]) set lowerCell to awayFromRiver([99, 106, 107, 114, 115, 121, 122, 123, 129, 130, 136, 137]) end if set buildingList to pickBuildings(4) set buildingList to shuffleList(buildingList) placeOneBuilding(lowerCell, the number of cast (getAt(buildingList, 1) & "." & the gridSize of gSimObject)) placeOneBuilding(lomidCell, the number of cast (getAt(buildingList, 2) & "." & the gridSize of gSimObject)) placeOneBuilding(upmidCell, the number of cast (getAt(buildingList, 3) & "." & the gridSize of gSimObject)) placeOneBuilding(upperCell, the number of cast (getAt(buildingList, 4) & "." & the gridSize of gSimObject)) set segmentDataA to makePathSegment(cell, lowerCell) set moveListA to getAt(segmentDataA, 1) set blockListA to getAt(segmentDataA, 2) set segmentDataB to makePathSegment(cell, lomidCell) set moveListB to getAt(segmentDataB, 1) set blockListB to getAt(segmentDataB, 2) if count(moveListA) <= count(moveListB) then set tempPathList to appendPathList(tempPathList, moveListA) set totalBlockList to appendBlocks(totalBlockList, blockListA) disconnectBuildings([lomidCell, blockListB]) set segmentDataA to makePathSegment(getLast(tempPathList), lomidCell) set moveListA to getAt(segmentDataA, 1) set blockListA to getAt(segmentDataA, 2) set segmentDataB to makePathSegment(getLast(tempPathList), upmidCell) set moveListB to getAt(segmentDataB, 1) set blockListB to getAt(segmentDataB, 2) if count(moveListA) <= count(moveListB) then set tempPathList to appendPathList(tempPathList, moveListA) set totalBlockList to appendBlocks(totalBlockList, blockListA) disconnectBuildings([upmidCell, blockListB]) set segmentDataA to makePathSegment(getLast(tempPathList), upmidCell) set moveListA to getAt(segmentDataA, 1) set blockListA to getAt(segmentDataA, 2) set segmentDataB to makePathSegment(getLast(tempPathList), upperCell) set moveListB to getAt(segmentDataB, 1) set blockListB to getAt(segmentDataB, 2) if count(moveListA) <= count(moveListB) then set tempPathList to appendPathList(tempPathList, moveListA) set totalBlockList to appendBlocks(totalBlockList, blockListA) disconnectBuildings([upperCell, blockListB]) set segmentData to makePathSegment(getLast(tempPathList), upperCell) else set tempPathList to appendPathList(tempPathList, moveListB) set totalBlockList to appendBlocks(totalBlockList, blockListB) disconnectBuildings([upmidCell, blockListA]) set segmentData to makePathSegment(getLast(tempPathList), upmidCell) end if set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1)) set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2)) else set tempPathList to appendPathList(tempPathList, moveListB) set totalBlockList to appendBlocks(totalBlockList, blockListB) disconnectBuildings([lomidCell, blockListA]) set segmentData to makePathSegment(getLast(tempPathList), lomidCell) set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1)) set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2)) if the connector of getAt(the cellList of gSimObject, upperCell) = 0 then set segmentData to makePathSegment(getLast(tempPathList), upperCell) set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1)) set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2)) end if end if else set tempPathList to appendPathList(tempPathList, moveListB) set totalBlockList to appendBlocks(totalBlockList, blockListB) disconnectBuildings([lowerCell, blockListA]) set segmentData to makePathSegment(getLast(tempPathList), lowerCell) set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1)) set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2)) if the connector of getAt(the cellList of gSimObject, upmidCell) = 0 then set segmentData to makePathSegment(getLast(tempPathList), upmidCell) set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1)) set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2)) end if set segmentData to makePathSegment(getLast(tempPathList), upperCell) set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1)) set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2)) end if set segmentData to makePathSegment(getLast(tempPathList), the goalCell of gSimObject) set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1)) set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2)) disconnectBuildings([lowerCell, lomidCell, upmidCell, upperCell, totalBlockList]) end if end if erasePath(tempPathList) return tempPathList end on makePathSegment cell, destCell set segmentList to [:] set blockList to [] set tempFinishedFlag to 0 set cellObject to getAt(the cellList of gSimObject, cell) if the level of gLevelObject = 3 then set dontCrossRiver to 0 set destObject to getAt(the cellList of gSimObject, destCell) if isCellAboveRiver(cell, cellObject) = isCellAboveRiver(destCell, destObject) then set dontCrossRiver to 1 end if end if repeat while tempFinishedFlag = 0 set newMove to 0 set spriteH to the horizValue of cellObject set spriteV to the vertValue of cellObject set destH to the horizValue of getAt(the cellList of gSimObject, destCell) set destV to the vertValue of getAt(the cellList of gSimObject, destCell) set Hdelta to abs(spriteH - destH) set Vdelta to abs(spriteV - destV) set availableMoveList to availForPath(cell, cellObject, dontCrossRiver) if spriteV > destV then if spriteH > destH then if Hdelta > Vdelta then set newMove to tryMove([#w, #NW, #SW, #n, #NE, #E, #s, #SE], availableMoveList) else set newMove to tryMove([#NW, #n, #w, #NE, #SW, #E, #s, #SE], availableMoveList) end if else if spriteH < destH then if Hdelta > Vdelta then set newMove to tryMove([#E, #NE, #NW, #n, #SE, #w, #s, #SW], availableMoveList) else set newMove to tryMove([#NE, #n, #E, #NW, #SE, #w, #s, #SW], availableMoveList) end if else set newMove to tryMove([#n, #NW, #NE, #w, #E, #SW, #SE, #s], availableMoveList) end if end if else if spriteV = destV then if spriteH > destH then set newMove to tryMove([#w, #SW, #NW, #s, #n, #SE, #NE, #E], availableMoveList) else set newMove to tryMove([#E, #NE, #SE, #n, #s, #NW, #SW, #w], availableMoveList) end if else if spriteH > destH then if Hdelta > Vdelta then set newMove to tryMove([#w, #SW, #NW, #s, #SE, #n, #E, #NE], availableMoveList) else set newMove to tryMove([#SW, #s, #w, #NW, #SE, #n, #E, #NE], availableMoveList) end if else if spriteH < destH then if Hdelta > Vdelta then set newMove to tryMove([#E, #SE, #NE, #s, #SW, #n, #w, #NW], availableMoveList) else set newMove to tryMove([#SE, #s, #E, #NE, #SW, #n, #w, #NW], availableMoveList) end if else set newMove to tryMove([#s, #SW, #SE, #w, #E, #NW, #NE, #n], availableMoveList) end if end if end if end if set cell to cell + getProp(the moveList of gSimObject, newMove) set cellObject to getAt(the cellList of gSimObject, cell) addProp(segmentList, newMove, cell) if the tileType of cellObject = #River then set dontCrossRiver to 1 set riverTileName to char 1 of the name of cast the tileNum of cellObject set bridgeData to getProp(getProp(the bridgeList of gSimObject, riverTileName), newMove) set newMove to getAt(bridgeData, 2) set cell to cell + getProp(the moveList of gSimObject, newMove) set cellObject to getAt(the cellList of gSimObject, cell) addProp(segmentList, newMove, cell) end if repeat with adjVector in the adjacentList of cellObject set adjCell to cell + getProp(the moveList of gSimObject, adjVector) set adjObject to getAt(the cellList of gSimObject, adjCell) if the tileType of adjObject = #Building then set the connector of adjObject to 1 set newBlocks to blockCrossings(adjCell, adjVector) repeat with blockedCell in newBlocks add(blockList, blockedCell) end repeat if adjCell = destCell then set tempFinishedFlag to 1 end if exit repeat end if if adjCell = destCell then set tempFinishedFlag to 1 exit repeat end if end repeat end repeat return [segmentList, blockList] end on availForPath cell, cellObject, dontCrossRiver set adjacentCellList to the adjacentList of getAt(the cellList of gSimObject, cell) set availableMoveList to [] repeat with x = 1 to count(adjacentCellList) add(availableMoveList, getAt(adjacentCellList, x)) end repeat set filledCellList to [] repeat with x = 1 to count(availableMoveList) set adjVector to getAt(availableMoveList, x) set adjCell to cell + getProp(the moveList of gSimObject, adjVector) set adjObj to getAt(the cellList of gSimObject, adjCell) if (the tileType of adjObj = #Road) or (the tileType of adjObj = #Bridge) or (the tileType of adjObj = #Goal) or (the tileType of adjObj = #Building) then add(filledCellList, adjVector) next repeat end if if the tileType of adjObj = #River then if (checkBlockForPath(adjCell, adjObj, adjVector) = 1) or (dontCrossRiver = 1) then add(filledCellList, adjVector) end if end if end repeat repeat with x = 1 to count(filledCellList) set filledCell to getAt(filledCellList, x) set position to getPos(availableMoveList, filledCell) if position <> 0 then deleteAt(availableMoveList, position) end if end repeat return availableMoveList end on checkBlockForPath adjCell, adjObj, adjVector set riverTileName to char 1 of the name of cast the tileNum of adjObj set bridgeList to getProp(the bridgeList of gSimObject, riverTileName) set bridgeData to getProp(bridgeList, adjVector) set exitDir to getAt(bridgeData, 2) set otherSideCell to adjCell + getProp(the moveList of gSimObject, exitDir) set otherSideObj to getAt(the cellList of gSimObject, otherSideCell) if getPos(the adjacentList of adjObj, exitDir) = 0 then set blockedFlag to 1 end if if (the tileType of otherSideObj = #Road) or (the tileType of otherSideObj = #River) then set blockedFlag to 1 else set blockedFlag to 0 end if return blockedFlag end on erasePath segmentList repeat with x = 1 to count(segmentList) set cellObj to getAt(the cellList of gSimObject, getAt(segmentList, x)) set the tileType of cellObj to the startTileType of cellObj end repeat end on fillPath segmentList repeat with x = 1 to count(segmentList) set cellObj to getAt(the cellList of gSimObject, getAt(segmentList, x)) if the startTileType of cellObj <> #River then set the tileType of cellObj to #Road next repeat end if set the tileType of cellObj to #Bridge end repeat end on placeOneBuilding whichCell, buildingCastnum set cellObj to getAt(the cellList of gSimObject, whichCell) set the startTileNum of cellObj to buildingCastnum set the startTileType of cellObj to #Building set the tileNum of cellObj to buildingCastnum set the tileType of cellObj to #Building end on tryMove moveList, availableMoveList repeat with vector in moveList if getOne(availableMoveList, vector) <> 0 then set newMove to vector exit repeat next repeat end if set newMove to 0 end repeat return newMove end on disconnectBuildings buildingDataList repeat with x = 1 to count(buildingDataList) - 1 set cell to getAt(buildingDataList, x) set the connector of getAt(the cellList of gSimObject, cell) to 0 end repeat set blockList to getLast(buildingDataList) repeat with cell in blockList set cellObj to getAt(the cellList of gSimObject, cell) initAdjacentList(cellObj) end repeat end on awayFromRiver regionList set done to 0 repeat while done = 0 set index to random(count(regionList)) set cell to getAt(regionList, index) if byTheRiver(cell) = 1 then deleteAt(regionList, index) next repeat end if set done to 1 end repeat return cell end on byTheRiver cell set occupied to 0 repeat with adjVector in the adjacentList of getAt(the cellList of gSimObject, cell) set adjCell to cell + getProp(the moveList of gSimObject, adjVector) set occupied to checkForRiver(adjCell) if occupied = 1 then exit repeat end if end repeat return occupied end on checkForRiver cell set cellObj to getAt(the cellList of gSimObject, cell) if the tileType of cellObj = #River then set occupied to 1 else set occupied to 0 end if return occupied end on isCellAboveRiver cell, cellObject set vertValue to the vertValue of cellObject set vOffset to (the columns of gSimObject * 2) - 1 set aboveRiverFlag to 0 set checkCell to cell + vOffset repeat while checkCell < count(the cellList of gSimObject) set checkObj to getAt(the cellList of gSimObject, checkCell) if (the tileType of checkObj = #River) or (the tileType of checkObj = #Bridge) then set aboveRiverFlag to 1 exit repeat next repeat end if set checkCell to checkCell + vOffset end repeat return aboveRiverFlag end on appendPathList mainList, addOnList fillPath(addOnList) repeat with x = 1 to count(addOnList) addProp(mainList, getPropAt(addOnList, x), getAt(addOnList, x)) end repeat return mainList end on appendBlocks totalBlockList, blockList repeat with block in blockList add(totalBlockList, block) end repeat return totalBlockList end on pickBuildings howMany set buildingList to [] repeat with x = 2 to 5 add(buildingList, getAt(the scenarioData of gSimObject, x)) end repeat set numberToDelete to 4 - howMany repeat while numberToDelete > 0 deleteAt(buildingList, random(count(buildingList))) set numberToDelete to numberToDelete - 1 end repeat return buildingList end